﻿
<div class="form-horizontal" ms-controller="LCSP">
    <div class="form-group">
        <label class="col-xs-2 control-label">表单申请人</label>
        <div class="col-xs-4">
            <p class="form-control-static" ms-text="modelData.ShenQingRen"></p>
        </div>
    </div>
    <div class="form-group">
        <label class="col-xs-2 control-label">流程类别</label>
        <div class="col-xs-9">
            <label class="control-label" style=" font-weight:normal;">{{modelData.LeiBie}}</label>
        </div>
    </div>
    <div id="tempcontent">
        {{tempcontent|html}}
    </div>
    <div class="form-group">
        <label class="col-xs-2 control-label">附件</label>
        <div class="col-xs-9">
            <input type="text" ms-duplex="modelData.Files" class="span2  szhl_Upload form-control" />
        </div>
    </div>
</div>
<div style="display:none" id="hidecontent"></div>
<script>
    var tempmodel = avalon.define({
        $id: "LCSP",
        name: "流程审批",

        ColumnData: [],
        SPUserData: [],
        TempData: [],
        modelData: { "ShenQingRen": ComFunJS.convertuser(ComFunJS.getCookie('username')), "LeiBie": "", "Content": "", "Files": "" },
        PDID: ComFunJS.getQueryString("PDID", ""),
        tempcontent: localStorage.getItem("lcsptemp") ? localStorage.getItem("lcsptemp") : "",
        iswf: true,//是否属于流程表单
        inittemp: function (strId) {
            //加载初始化数据
            $.getJSON('/API/FTAPI.ashx?Action=GETLCSPMODEL', { P1: strId, P2: tempmodel.PDID }, function (resultData) {
                if (resultData.ErrorMsg == "") {
                    if (strId) {
                        tempmodel.modelData = resultData.Result;
                        tempmodel.TempData = eval(resultData.Result.Content);//提交表单保存的值
                        $("#hidecontent").append(resultData.Result1.Tempcontent).children().each(function (i, dom) {
                            if ($(dom).attr("datatype") == tempmodel.TempData[i].datatype && $(dom).attr("dataname") == tempmodel.TempData[i].dataname) {
                                if (tempmodel.TempData[i].datatype == "text") {
                                    $(this).find("input").attr("value", tempmodel.TempData[i].value)
                                } else if (tempmodel.TempData[i].datatype == "select") {
                                    $(this).find("select").children().each(function () {
                                        if (tempmodel.TempData[i].value == $(this).val())
                                        {
                                            $(this).attr("selected", true);
                                        }
                                    })
                                } else if (tempmodel.TempData[i].datatype == "check") {
                                    $(this).find("input[type=checkbox][value='" + tempmodel.TempData[i].value + "']").attr("checked", true);
                                } else if (tempmodel.TempData[i].datatype == "textarea") {
                                    $(this).find("textarea").html(tempmodel.TempData[i].value)
                                }
                            }
                        })
                        tempmodel.tempcontent = $("#hidecontent").html();
                        $("#hidecontent").remove();
                    } else {
                        tempmodel.tempcontent = resultData.Result1.Tempcontent;
                        tempmodel.modelData.LeiBie = resultData.Result1.ProcessName;//流程名称
                    }
                    setTimeout("ComFunJS.initForm()", 500);
                }
            })
        },//初始化
        SaveData: function (btdom, piid) {
            $("#tempcontent").children().each(function () {
                var tempValue = "";
                if ($(this).attr("datatype") != "check") {
                    tempValue = $(this).find("input,select,textarea").val();
                } else if ($(this).attr("datatype") == "check") {
                    tempValue = $(this).find("input[type=checkbox]:checked").val();
                }
                tempmodel.TempData.push({ dataname: $(this).attr("dataname"), datatype: $(this).attr("datatype"), value: tempValue })
            })
            var content = JSON.stringify(tempmodel.TempData.$model);
           // console.debug(content)
            var data = tempmodel.modelData.$model;
            data.Content = content;//保存模版对应的数据

            if (piid) {
                data.intProcessStanceid = piid;
            }
            var modelValue = JSON.stringify(data);
            $.post("/API/FTAPI.ashx?ACTION=ADDLCSP", { P1: modelValue }, function (result) {
                var jsonresult = $.parseJSON(result)
                btdom.removeClass("disabled").find("i").hide();
                if ($.trim(jsonresult.ErrorMsg) == "") {
                    ComFunJS.winsuccessnew("操作成功");
                } else {
                    if (pmodel.DELPIINFO && piid) {
                        pmodel.DELPIINFO(piid);
                    }
                }
            });

        },
    });//@ sourceURL=LCSP.js;


</script>
